Close Menu
SalesforceCodex
    Facebook X (Twitter) Instagram
    Trending
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    • How to Suppress PMD Warnings in Salesforce Apex
    • Top 10 PMD Issues Salesforce Developers Should Focus on in Apex
    • How to Use Graph API for Outlook-Salesforce Connection
    Facebook X (Twitter) Instagram
    SalesforceCodex
    Subscribe
    Thursday, May 29
    • Home
    • Architecture
    • Salesforce
      • News
      • Apex
      • Integration
      • Books Testimonial
    • Questions
    • Certification
      • How to Prepare for Salesforce Integration Architect Exam
      • Certification Coupons
    • Integration Posts
    • Downloads
    • About Us
      • Privacy Policy
    SalesforceCodex
    Home»Salesforce»Extract License Plate Number from Image In Salesforce

    Extract License Plate Number from Image In Salesforce

    Dhanik Lal SahniBy Dhanik Lal SahniJune 17, 2020Updated:December 26, 20242 Comments3 Mins Read
    Facebook Twitter Pinterest LinkedIn Tumblr Email
    Extract License Plate Number from Image In Salesforce
    Share
    Facebook Twitter LinkedIn Pinterest Email

    Last week I got a request about extracting the vehicle license plate numbers. Requester wanted to extract the license plate number from the image. I was not sure that we have a specific API for this request. After analysis, I found License Plate Number APIs which can extract plate numbers from images.

    To extract the license plate number from the image in Salesforce, we have to complete the below steps

    1. Get the test credential from RapidAPI
    2. Create Apex Class to extract Plate Number from the image
    3. Call Apex class from Flow
    4. Add button on page layout and call flow

    1. Get the test credential from RapidAPI

    Create an account in RapidAPI.com to test License Plate Recognition API. Once the account is created, go to https://rapidapi.com/macgyverapi/api/license-plate-recognition1 and get a test credential for this API.

    2. Create Apex Class to extract Plate Number from image

    Once test account and API credential are created, let us create apex class which will be extract license plate number from image.

    API Url : https://macgyverapi-license-plate-recognition-v1.p.rapidapi.com/

    Above API will need image url to process so we have to get url for our uploaded image in Salesforce record. Sample request for this API is below

    {
        "id": "3X5D3d2k",
        "key": "free",
        "data": {
            "image_url": "https://storage.googleapis.com/marketing-files/program-markdown-assets/license-detection/license-plate.jpg",
            "country": "us",
            "numberCandidates": 2
        }
    }

    External Url for Image:

    We can use ContentDistribution object for getting image url from uploaded image. We can create public image link when we upload file. Create trigger for creating public link.

    trigger ContentVersionExternalLink on ContentVersion (after insert) {
    	ContentTriggerHandler.createPublicLinkForFile(trigger.new);
    }

    ContentTriggerHandler class will help in creating public link for uploaded image. This class will be called from ContentVersionExternalLink trigger.

    public class ContentTriggerHandler {
        public static void createPublicLinkForFile(List<ContentVersion> contentVersions){
            ContentDistribution[] distributionsToInsert = new List<ContentDistribution>();
            Set<Id> contentDocId = new Set<Id>();
            for(ContentVersion objContentVersion : contentVersions){
                contentDocId.add(objContentVersion.ContentDocumentId);
            }
            for(ContentVersion objContentVersion : contentVersions){
               distributionsToInsert.add(createContentDistribution(objContentVersion.Id));
            }
            insert distributionsToInsert;
        }
        
        public static ContentDistribution createContentDistribution(Id contentVersionId){
            ContentDistribution newDist = new ContentDistribution();
            newDist.ContentVersionId = contentVersionId;
            newDist.Name = 'External Link';
            newDist.PreferencesNotifyOnVisit = false;
            newDist.PreferencesAllowViewInBrowser = true;
            return newDist;
        }
    }

    We also have to make uploaded file visible using ContentDocumentLink. Create trigger for this like below code.

    trigger ContentDocumentLinkTrigger on ContentDocumentLink (before insert) {
        for(ContentDocumentLink l:Trigger.new) {
            l.Visibility='AllUsers';
        }
    }

    Now we will get public downloadable link of uploaded image. Let us create apex class which will extract plate number.

    Complete Apex Code:

    Above code will also update vehicle license plate number in case object. Create Plate Number field in case object to store extracted plate number.

    Note: Add API url in remote site setting or you can use named credential to avoid this.

    3. Call Apex class from Flow

    After apex class created, we have to call this apex class from flow or lightning component. I have used flow to use as standard feature instead of custom code.

    Here is complete flow process.

    Variables :

    Create two variables recordId and varRecordId.

    This variable will hold value when record id passed from record page to flow.

    Assignment Logic :

    Create assignment logic to assign value from recordId to varRecordId. recordId is passed from record page.

    Action Method :

    Call apex class from action flow. Pass varRecordId to apex method. @InvocableMethod annotation is required for calling any apex method from flow.

    4. Add button on page layout and call flow

    Add a new action button in case object and then put this button on page layout. This button will call flow to update plate number in field.

    Test Page;

    References:

    https://rapidapi.com/macgyverapi/api/license-plate-recognition1

    https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_intro_what_is_apex.htm

    apex apex rest api flow rest api
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
    Previous ArticleGenerate own code for Apex using Salesforce CLI
    Next Article Create OCR App using Salesforce Einstein OCR API
    Dhanik Lal Sahni
    • Website
    • Facebook
    • X (Twitter)

    With over 18 years of experience in web-based application development, I specialize in Salesforce technology and its ecosystem. My journey has equipped me with expertise in a diverse range of technologies including .NET, .NET Core, MS Dynamics CRM, Azure, Oracle, and SQL Server. I am dedicated to staying at the forefront of technological advancements and continuously researching new developments in the Salesforce realm. My focus remains on leveraging technology to create innovative solutions that drive business success.

    Related Posts

    By Dhanik Lal Sahni4 Mins Read

    How to Build a Generic Modal Window in Lightning Web Component

    May 26, 2025
    By Dhanik Lal Sahni6 Mins Read

    Top 10 Salesforce Flow Features of Salesforce Summer ’25

    May 11, 2025
    By Dhanik Lal Sahni6 Mins Read

    Unlock the Power of Vibe Coding in Salesforce

    April 30, 2025
    View 2 Comments

    2 Comments

    1. Pingback: Create OCR App using Salesforce Einstein OCR API | SalesforceCodex

    2. Dhanik Lal Sahni on December 7, 2020 6:21 pm

      Hey Smriti,

      Looks like this API is down. Their website is also down, looks like they have stop their service.

      I will write blog with some other API for this use case.

      Thank You for letting me know.

      Dhanik

      Reply
    Leave A Reply Cancel Reply

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) file upload (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (30) Lightning web component (62) lwc (51) named credential (8) news (4) optimize apex code (4) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (141) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Ranked #1 SALESFORCE DEVELOPER BLOG BY SALESFORCEBEN.COM
    Featured on Top Salesforce Developer Blog By ApexHours
    Recent Posts
    • How to Build a Generic Modal Window in Lightning Web Component
    • Top 10 Salesforce Flow Features of Salesforce Summer ’25
    • Unlock the Power of Vibe Coding in Salesforce
    • How to Implement Dynamic Queueable Chaining in Salesforce Apex
    • How to Implement Basic Queueable Chaining in Salesforce Apex
    Ranked in Top Salesforce Blog by feedspot.com
    RSS Recent Stories
    • How to Connect Excel to Salesforce to Manage Your Data and Metadata February 9, 2025
    • Difference Between With Security and Without Security in Apex January 2, 2025
    • Top Reasons to Love Salesforce Trailhead: A Comprehensive Guide December 5, 2024
    • How to Utilize Apex Properties in Salesforce November 3, 2024
    • How to Choose Between SOQL and SOSL Queries July 31, 2024
    Archives
    Categories
    Tags
    apex (111) apex code best practice (8) apex rest (11) apex trigger best practices (4) architecture (22) Asynchronous apex (9) AWS (5) batch apex (9) batch processing (4) code optimization (8) code review tools (3) custom metadata types (5) design principle (9) file upload (3) flow (15) future method (4) google (6) google api (4) integration (19) integration architecture (6) lighting (8) lightning (64) lightning-combobox (5) lightning-datatable (10) lightning component (30) Lightning web component (62) lwc (51) named credential (8) news (4) optimize apex code (4) Permission set (4) pmd (3) Queueable (9) rest api (23) S3 Server (4) salesforce (141) salesforce apex (46) salesforce api (4) salesforce api integration (5) Salesforce Interview Question (4) salesforce news (5) salesforce question (5) solid (6) tooling api (5) Winter 20 (8)

    Get our newsletter

    Want the latest from our blog straight to your inbox? Chucks us your detail and get mail when new post is published.
    * indicates required

    Facebook X (Twitter) Instagram Pinterest YouTube Tumblr LinkedIn Reddit Telegram
    © 2025 SalesforceCodex.com. Designed by Vagmine Cloud Solution.

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.